#ANALYSIS CL PAPER WITHOUT CONTROL VARIABLES#
install.packages("dotwhisker")
install.packages("psych")
install.packages ("tidyverse")
install.packages("coefplot")
install.packages("sjPlot")
install.packages("sjmisc")
install.packages ("sjlabelled")

library(dotwhisker)
library(dplyr)
library(psych)
library(ggplot2)
library(tidyverse)
library(coefplot)
library(ggsci)
library(gridExtra)
library(sjPlot)
library(sjmisc)
library(sjlabelled)
library(gt)
library(forcats)

#opening dataset
read.csv("cldataset.csv", sep = ";")
View(cldataset)
str(cldataset)

#TIBBLES#
exp1cltibble <- cldataset%>% select(pref_e1,imp_e1,treatyyy_e1, 
                                    treatnyn_e1,treatnyy_e1,treatnny_e1,
                                    treatyyn_e1,treatyny_e1,treatynn_e1,
                                    treatnnn_e1,tru_e1,int_eff_ind_e1,ex_eff_e1,
                                    acc_e1,Con_eff_e1, rec_e1)
view(exp1cltibble) #tibble first experiment

exp2cltibble <- cldataset%>% select(pref_e2,imp_e2,treatyyy_e2,
                                    treatnnn_ex2,treatynn_e2,treatyny_e2,
                                    treatyyn_ex2,treatnny_e2,treatnyy_e2,
                                    treatnyn_e2,tru_e2,Int_eff_indv_e2,
                                    ex_eff_e2,acc_e2,Con_eff_e2, rec_e2)
view(exp2cltibble) #tibble second experiment

#DUMMIES#
#making the new facilitation variable
exp1cltibble <- exp1cltibble%>% as_tibble(.) %>%
  mutate(facilitation = dplyr::case_when(
    treatyyy_e1==1 ~ 1,
    treatyyn_e1==4 ~ 1,
    treatyny_e1==4 ~ 1,
    treatynn_e1==4 ~ 1
  ))
view(exp1cltibble)

exp2cltibble <- exp2cltibble%>% as_tibble(.) %>%
  mutate(facilitation = dplyr::case_when(
    treatyyy_e2==4 ~ 1,
    treatynn_e2==4 ~ 1,
    treatyny_e2==4 ~ 1,
    treatyyn_ex2==4 ~ 1
  ))
view(exp2cltibble)

#changing NA in 0
exp1cltibble <- exp1cltibble%>% as_tibble(.) %>%
  mutate(facilitation = dplyr::case_when(
    is.na(facilitation) ~ "0",
    TRUE ~ as.character(facilitation)))

view(exp1cltibble)

exp2cltibble <- exp2cltibble%>% as_tibble(.) %>%
  mutate(facilitation = dplyr::case_when(
    is.na(facilitation) ~ "0",
    TRUE ~ as.character(facilitation)))

view(exp2cltibble)

#making the uptake variable
exp1cltibble <- exp1cltibble%>% as_tibble(.) %>%
  mutate(uptake = dplyr::case_when(
    treatyyy_e1==1 ~ 1,
    treatnyn_e1==4 ~ 1,
    treatnyy_e1==4 ~ 1,
    treatyyn_e1==4 ~ 1
  ))

exp1cltibble <- exp1cltibble%>% as_tibble(.) %>%
  mutate(uptake = dplyr::case_when(
    is.na(uptake) ~ "0",
    TRUE ~ as.character(uptake)))
view(exp1cltibble)

exp2cltibble <- exp2cltibble%>% as_tibble(.) %>%
  mutate(uptake = dplyr::case_when(
    treatyyy_e2==4 ~ 1,
    treatyyn_ex2==4 ~ 1,
    treatnyy_e2==4 ~ 1,
    treatnyn_e2==4 ~ 1
  ))

exp2cltibble <- exp2cltibble%>% as_tibble(.) %>%
  mutate(uptake = dplyr::case_when(
    is.na(uptake) ~ "0",
    TRUE ~ as.character(uptake)))
view(exp2cltibble)


#creating the loser subsample
exp1cltibble <- exp1cltibble%>% as_tibble(.) %>%
  mutate(loser = dplyr::case_when (
    (pref_e1==1 & treatyyy_e1==1) ~ 0,
    (pref_e1==1 & treatnyy_e1==4) ~ 0,
    (pref_e1==1 & treatnny_e1==4) ~ 0,
    (pref_e1==1 & treatyny_e1==4) ~ 0,
    (pref_e1==2 & treatnyn_e1==4) ~ 0,
    (pref_e1==2 & treatyyn_e1==4) ~ 0,
    (pref_e1==2 & treatynn_e1==4) ~ 0,
    (pref_e1==2 & treatnnn_e1==4) ~ 0,
    (pref_e1==1 & treatnyn_e1==4) ~ 1,
    (pref_e1==1 & treatyyn_e1==4) ~ 1,
    (pref_e1==1 & treatynn_e1==4) ~ 1,
    (pref_e1==1 & treatnnn_e1==4) ~ 1,
    (pref_e1==2 & treatyyy_e1==1) ~ 1,
    (pref_e1==2 & treatnyy_e1==4) ~ 1,
    (pref_e1==2 & treatnny_e1==4) ~ 1,
    (pref_e1==2 & treatyny_e1==4) ~ 1))
view(exp1cltibble)
e1loser <- exp1cltibble[exp1cltibble$loser =="1",]
view(e1loser)

exp2cltibble <- exp2cltibble%>% as_tibble(.) %>%
  mutate(loser = dplyr::case_when (
    (pref_e2==1 & treatyyy_e2==4) ~ 0,
    (pref_e2==1 & treatnyy_e2==4) ~ 0,
    (pref_e2==1 & treatnny_e2==4) ~ 0,
    (pref_e2==1 & treatyny_e2==4) ~ 0,
    (pref_e2==2 & treatnyn_e2==4) ~ 0,
    (pref_e2==2 & treatyyn_ex2==4) ~ 0,
    (pref_e2==2 & treatynn_e2==4) ~ 0,
    (pref_e2==2 & treatnnn_ex2==4) ~ 0,
    (pref_e2==1 & treatnyn_e2==4) ~ 1,
    (pref_e2==1 & treatyyn_ex2==4) ~ 1,
    (pref_e2==1 & treatynn_e2==4) ~ 1,
    (pref_e2==1 & treatnnn_ex2==4) ~ 1,
    (pref_e2==2 & treatyyy_e2==4) ~ 1,
    (pref_e2==2 & treatnyy_e2==4) ~ 1,
    (pref_e2==2 & treatnny_e2==4) ~ 1,
    (pref_e2==2 & treatyny_e2==4) ~ 1))
view(exp2cltibble)
e2loser <- exp2cltibble[exp2cltibble$loser =="1",]
view(e2loser)

#MODELS#

#empowerment
emp1 <- lm(int_eff_ind_e1 ~ facilitation + 
             uptake, data=exp1cltibble) #model e1 internal efficacy gen

emp3<- lm(Con_eff_e1 ~ facilitation + 
            uptake, data=exp1cltibble) #model e1 int efficacy spec

emp5<- lm(acc_e1 ~ facilitation + 
            uptake, data=exp1cltibble) #model e1 access


emp2<- lm(Int_eff_indv_e2 ~ facilitation + 
            uptake, data=exp2cltibble) #model e2 internal efficacy gen

emp4<- lm(Con_eff_e2 ~ facilitation + 
            uptake, data=exp2cltibble) #model e2 int efficacy spec

emp6<- lm(acc_e2 ~ facilitation + 
            uptake, data=exp2cltibble)#model e2 access

#empowerment losers
emp7<- lm(int_eff_ind_e1 ~ facilitation + 
            uptake, data=e1loser) #loser e1 int eff

emp9<- lm(Con_eff_e1 ~ facilitation + 
            uptake, data=e1loser) #loser e1 int eff spec!!!!!

emp11<- lm(acc_e1 ~ facilitation + 
             uptake, data=e1loser) #loser e1 access


emp8<- lm(Int_eff_indv_e2 ~ facilitation + 
            uptake, data=e2loser)  #loser e2 int eff

emp10<-lm(Con_eff_e2 ~ facilitation + 
            uptake, data=e2loser) #loser e2 int eff spec!!!!!

emp12<- lm(acc_e2 ~ facilitation + 
             uptake, data=e2loser) #loser e2 access

#support
fav1 <- lm(tru_e1 ~ facilitation + 
             uptake, data=exp1cltibble) #model e1 trust

fav3<- lm(ex_eff_e1 ~ facilitation + 
            uptake, data=exp1cltibble) #model e1 external efficacy


fav2 <- lm(tru_e2 ~ facilitation + 
             uptake, data=exp2cltibble) #model e2 trust

fav4<- lm(ex_eff_e2 ~ facilitation + 
            uptake, data=exp2cltibble) #model e2 external efficacy


#support losers
fav5 <- lm(tru_e1 ~ facilitation + 
             uptake, data=e1loser) #loser e1 trust

fav7 <- lm(ex_eff_e1 ~ facilitation + 
             uptake, data=e1loser) #loser e1 external efficacy


fav6 <- lm(tru_e2 ~ facilitation + 
             uptake, data=e2loser) #loser e2 trust

fav8 <- lm(ex_eff_e2 ~ facilitation + 
             uptake, data=e2loser) #loser e2 external efficacy

#COEFFICIENT PLOTS#

#coeffplot support e1
multiplot(fav1, fav3, predictors=c('uptake', 'facilitation'), 
          numberAngle=0, zeroType=1,
          newNames=c("uptake1"="Uptake", "facilitation1"="Invitation"),
          pointSize=4,lwdInner=0.8,innerCI=2, outerCI=0, dodgeHeight=0.3) + 
  theme_bw() +
  labs(title="Figure 1. Effects on political support (Experiment 1)", 
       caption =
         "Notes: The estimates are the results of an OLS regression;\nITT analysis; Non-standardized coefficients are presented; CI = 95 percent;\nN external efficacy = 1214; N trust = 1218;\nThe corresponding table is Table 2 in Appendix D.") +
  scale_color_manual(labels=c("fav3"= "External Efficacy",
                              "fav1"="Trust"),
                     values = c("fav3"="#fdb0c0", "fav1"= "#009E73")) +
  theme(legend.position = "right", 
        plot.caption = element_text(face = "italic", hjust = 0,
                                    lineheight = 1)) +
  scale_y_discrete(limits=c("Uptake", "Invitation")) +
  xlim(-0.6,1.5) +
  guides(color=guide_legend("Political support")) +
  ylab ("")

#coeffplot support e2
multiplot(fav2, fav4, predictors=c('uptake', 'facilitation'), 
          numberAngle=0, zeroType=1,
          newNames=c("uptake1"="Uptake", "facilitation1"="Invitation"),
          pointSize=4,lwdInner=0.8,innerCI=2, outerCI=0, dodgeHeight=0.3) + 
  theme_bw() +
  labs(title="Figure 2. Effects on political support (Experiment 2)", 
       caption =
         "Notes: The estimates are the results of an OLS regression;\nITT analysis; Non-standardized coefficients are presented; CI = 95 percent;\n N external efficacy = 1215; N trust = 1216; \nThe corresponding table is Table 2 in Appendix D.") +
  scale_color_manual(labels=c("fav4"= "External Efficacy",
                              "fav2"="Trust"),
                     values = c("fav4"="#fdb0c0", "fav2"= "#009E73")) +
  theme(legend.position = "right",
        plot.caption = element_text(face = "italic", hjust = 0,
                                    lineheight = 1)) +
  scale_y_discrete(limits=c("Uptake", "Invitation")) +
  xlim(-0.6,1.5) +
  guides(color=guide_legend("Political support")) +
  ylab ("")

#coeffplot empowerment e1
multiplot(emp1, emp3, emp5, predictors=c('uptake', 'facilitation'), 
          numberAngle=0, zeroType=1,
          newNames=c("uptake1"="Uptake", "facilitation1"="Invitation"),
          pointSize=4,lwdInner=0.8,innerCI=2, outerCI=0, dodgeHeight=0.3) + 
  theme_bw() +
  labs(title="Figure 3. Effects on empowerment (Experiment 1)", 
       caption =
         "Notes: The estimates are the results of an OLS regression;\nITT analysis; Non-standardized coefficients are presented; CI = 95 percent;\nN access = 1209; N internal efficacy (specific) = 1208; N internal efficacy = 1216; \nThe corresponding table is Table 3 in Appendix D.") +
  scale_color_manual(labels=c("emp5"="Access", 
                              "emp3"= "Internal Efficacy (Specific)",
                              "emp1"="Internal Efficacy"),
                     values = c("emp5"="#56B4E9",
                                "emp3"="#E69F00",
                                "emp1"= "#AF8FE9")) +
  theme(legend.position = "right", 
        plot.caption = element_text(face = "italic", hjust = 0,
                                    lineheight = 1)) +
  scale_y_discrete(limits=c("Uptake", "Invitation")) +
  xlim(-0.6,1.5) +
  guides(color=guide_legend("Empowerment")) +
  ylab ("")

#coeffplot empowerment e2
multiplot(emp2, emp4, emp6, predictors=c('uptake', 'facilitation'), 
          numberAngle=0, zeroType=1,
          newNames=c("uptake1"="Uptake", "facilitation1"="Invitation"),
          pointSize=4,lwdInner=0.8,innerCI=2, outerCI=0, dodgeHeight=0.3) + 
  theme_bw() +
  labs(title = "Figure 4. Effects on empowerment (Experiment 2)",
       caption =
         "Notes: The estimates are the results of an OLS regression;\nITT analysis; Non-standardized coefficients are presented; CI = 95 percent;\nN access = 1213; N internal efficacy (specific) = 1213; N internal efficacy = 1216; \nThe corresponding table is Table 3 in Appendix D.") +
  scale_color_manual(labels=c("emp6"="Access",
                              "emp4"= "Internal Efficacy (Specific)",
                              "emp2"="Internal Efficacy"),
                     values = c("emp6"="#56B4E9",
                                "emp4"="#E69F00",
                                "emp2"= "#AF8FE9")) +
  theme(legend.position = "right",
        plot.caption = element_text(face = "italic", hjust = 0,
                                    lineheight = 1)) +
  scale_y_discrete(limits=c("Uptake", "Invitation")) +
  xlim(-0.6,1.5) +
  guides(color=guide_legend("Empowerment")) +
  ylab ("")


#coeffplot losers support e1
multiplot(fav5, fav7, predictors=c('uptake', 'facilitation'), 
          numberAngle=0, zeroType=1,
          newNames=c("uptake1"="Uptake", "facilitation1"="Invitation"),
          pointSize=4,lwdInner=0.8,innerCI=2, outerCI=0, dodgeHeight=0.3) + 
  theme_bw() +
  labs(title="Figure 5. Effects on political support for decision losers (Experiment 1)", 
       caption =
         "Notes: The estimates are the results of an OLS regression;\nITT analysis; Non-standardized coefficients are presented; CI = 95 percent;\n N external efficacy = 488; N trust = 490; \nThe corresponding table is Table 4 in Appendix D."
  ) +
  scale_color_manual(labels=c("fav7"= "External Efficacy",
                              "fav5"="Trust"),
                     values = c("fav7"="#fdb0c0",
                                "fav5"= "#009E73")) +
  theme(legend.position = "right",
        plot.caption = element_text(face = "italic", hjust = 0,
                                    lineheight = 1)) +
  scale_y_discrete(limits=c("Uptake", "Invitation")) +
  xlim(-0.6,1.5) +
  guides(color=guide_legend("Political support")) +
  ylab ("")

#coeffplot losers support e2
multiplot(fav6, fav8, predictors=c('uptake', 'facilitation'), 
          numberAngle=0, zeroType=1,
          newNames=c("uptake1"="Uptake", "facilitation1"="Invitation"),
          pointSize=4,lwdInner=0.8,innerCI=2, outerCI=0, dodgeHeight=0.3) + 
  theme_bw() +
  labs(title="Figure 6. Effects on political support for decision losers (Experiment 2)", 
       caption =
         "Notes: The estimates are the results of an OLS regression;\nITT analysis; Non-standardized coefficients are presented; CI = 95 percent;\n N external efficacy = 515; N trust = 515; \nThe corresponding table is Table 4 in Appendix D."
  ) +
  scale_color_manual(labels=c("fav8"= "External Efficacy",
                              "fav6"="Trust"),
                     values = c("fav8"="#fdb0c0",
                                "fav6"= "#009E73")) +
  theme(legend.position = "right",
        plot.caption = element_text(face = "italic", hjust = 0,
                                    lineheight = 1)) +
  scale_y_discrete(limits=c("Uptake", "Invitation")) +
  xlim(-0.6,1.5) +
  guides(color=guide_legend("Political support")) +
  ylab ("")


#coeffplot losers empowerment e1
#we use a different package here because of the colour order 
#and legenda that gives errors with our earlier used package

tibemp7 <- broom::tidy(emp7)%>% filter(term %in% c("facilitation1", "uptake1")) %>% 
  mutate(model = "Model1")
tibemp9 <- broom::tidy(emp9)%>% filter(term %in% c("facilitation1", "uptake1")) %>% 
  mutate(model = "Model2")
tibemp11 <- broom::tidy(emp11)%>% filter(term %in% c("facilitation1", "uptake1")) %>% 
  mutate(model = "Model3")
losempe1 <- rbind(tibemp7, tibemp9, tibemp11)

dwplot(losempe1, ci = 0.95, dodge_size = 0.3,
       dot_args = list(size = 4),
       whisker_args = list(size = 0.8),
       vars_order= c("facilitation1","uptake1"),
       model_order = c("Model3", "Model2", "Model1"),
       vline = geom_vline(xintercept = 0,
                          colour = "grey60",
                          linetype = 1)) %>%
  relabel_predictors(c(facilitation1 = "Invitation", uptake1= "Uptake")) + 
  ggtitle("Figure 7. Effects on empowerment for decision losers (Experiment 1)") +
  theme_bw() +
  scale_color_manual(name= "Empowerment", labels=c("Model1"="Internal Efficacy",
                                                   "Model2"= "Internal Efficacy (Specific)",
                                                   "Model3"="Access"),
                     values = c("Model1"= "#AF8FE9",
                                "Model2"="#E69F00",
                                "Model3"="#56B4E9")) +
  ylab("") +
  labs(caption =
         "Notes: The estimates are the results of an OLS regression;\nITT analysis; Non-standardized coefficients are presented; CI = 95 percent;\nN access = 485; N internal efficacy (specific) = 484; N internal efficacy = 489; \nThe corresponding table is Table 5 in Appendix D.",
       colour = "Empowerment") +
  theme(legend.position = "right",
        plot.caption = element_text(face = "italic", hjust = 0,
                                    lineheight = 1)) +  
  xlim(-0.6,1.5)

#coeffplot losers empowerment e2
#we use a different package here because of the colour order 
#and legenda that gives errors with our earlier used package

tibemp8 <- broom::tidy(emp8)%>% filter(term %in% c("facilitation1", "uptake1")) %>% 
  mutate(model = "Model1")
tibemp10 <- broom::tidy(emp10)%>% filter(term %in% c("facilitation1", "uptake1")) %>% 
  mutate(model = "Model2")
tibemp12 <- broom::tidy(emp12)%>% filter(term %in% c("facilitation1", "uptake1")) %>% 
  mutate(model = "Model3")
losempe2 <- rbind(tibemp8, tibemp10, tibemp12)

dwplot(losempe2, ci = 0.95, dodge_size = 0.3,
       dot_args = list(size = 4),
       whisker_args = list(size = 0.8),
       vars_order= c("facilitation1","uptake1"),
       model_order = c("Model3", "Model2", "Model1"),
       vline = geom_vline(xintercept = 0,
                          colour = "grey60",
                          linetype = 1)) %>%
  relabel_predictors(c(facilitation1 = "Invitation", uptake1= "Uptake")) + 
  ggtitle("Figure 8. Effects on empowerment for decision losers (Experiment 2)") +
  theme_bw() +
  scale_color_manual(name= "Empowerment", labels=c( "Model1"="Internal Efficacy",
                                                    "Model2"= "Internal Efficacy (Specific)",
                                                    "Model3"="Access"),
                     values = c("Model1"= "#AF8FE9",
                                "Model2"="#E69F00",
                                "Model3"="#56B4E9")) +
  ylab("") +
  labs(caption =
         "Notes: The estimates are the results of an OLS regression;\nITT analysis; Non-standardized coefficients are presented; CI = 95 percent;\nN access = 514; N internal efficacy (specific) = 514; N internal efficacy = 515; \nThe corresponding table is Table 5 in Appendix D.",
       colour="Empowerment"
  ) +
  theme(legend.position = "right",
        plot.caption = element_text(face = "italic", hjust = 0,
                                    lineheight = 1)) +  
  xlim(-0.6,1.5)



#COEFFICIENT TABLES#
#table support
tab_model(fav1, fav2, fav3, fav4, terms = c("facilitation1", "uptake1"), 
          pred.labels = c("Invitation", "Uptake"), 
          dv.labels = c("fav1"="Trust 1", "fav2"="Trust 2", 
                        "fav3"="External Efficacy 1", "fav4"="External Efficacy 2"), string.pred="Treatments",
          string.est="Coefficient (SE)", p.style="numeric_stars",
          auto.label = TRUE, show.ci = FALSE, collapse.se=TRUE,
          title="Table 2. ITT effects on support (full sample)")

#table empowerment
tab_model(emp1, emp2, emp3, emp4, emp5, emp6, terms = c("facilitation1", "uptake1"), 
          pred.labels = c("Invitation", "Uptake"), 
          dv.labels = c("emp1"="Internal Efficacy (General) 1", "emp2"="Internal Efficacy (General) 2", 
                        "emp3"="Internal Efficacy (Specific) 1", "emp4"="Internal Efficacy (Specific) 2",
                        "emp5"="Access 1", "emp6"="Access 2"), string.pred="Treatments",
          string.est="Coefficient (SE)", p.style="numeric_stars",
          auto.label = TRUE, show.ci = FALSE, show.fstat = TRUE, collapse.se=TRUE,
          title="Table 3. ITT effects on empowerment (full sample)")

#table loser support
tab_model(fav5, fav6, fav7, fav8, terms = c("facilitation1", "uptake1"), 
          pred.labels = c("Invitation", "Uptake"), 
          dv.labels = c("fav5"="Trust 1", "fav6"="Trust 2", 
                        "fav7"="External Efficacy 1", "fav8"="External Efficacy 2"), string.pred="Treatments",
          string.est="Coefficient (SE)", p.style="numeric_stars",
          auto.label = TRUE, show.ci = FALSE, collapse.se=TRUE,
          title="Table 4. ITT effects on support (subsample losers)")

#table loser empowerment
tab_model(emp7, emp8, emp9, emp10, 
          emp11, emp12, terms = c("facilitation1", "uptake1"), 
          pred.labels = c("Invitation", "Uptake"), 
          dv.labels = c("emp7"="Internal Efficacy (General) 1", "emp8"="Internal Efficacy (General) 2", 
                        "emp9"="Internal Efficacy (Specific) 1", "emp10"="Internal Efficacy (Specific) 2",
                        "emp11"="Access 1", "emp12"="Access 2"), string.pred="Treatments",
          string.est="Coefficient (SE)", p.style="numeric_stars",
          auto.label = TRUE, show.ci = FALSE, collapse.se=TRUE,
          title="Table 5. ITT effects on empowerment (subsample losers)")


#CACE ANALYSIS#
#Creating the compliant subsamples
e1cace <- exp1cltibble%>% as_tibble(.) %>%
  mutate(compliant = dplyr::case_when(
    rec_e1==3 ~ 1))

e1cace <- e1cace%>% as_tibble(.) %>%
  mutate(compliant = dplyr::case_when(
    is.na(compliant) ~ "0",
    TRUE ~ as.character(compliant)))

e1cace <- e1cace[e1cace$compliant =="1",]

e2cace <- exp2cltibble%>% as_tibble(.) %>%
  mutate(compliant = dplyr::case_when(
    rec_e2== 1 ~ 1))

e2cace <- e2cace%>% as_tibble(.) %>%
  mutate(compliant = dplyr::case_when(
    is.na(compliant) ~ "0",
    TRUE ~ as.character(compliant)))

e2cace <- e2cace[e2cace$compliant =="1",]
view(e2cace)

#subsample loser compliant
e1losercom <- e1cace[e1cace$loser =="1",]
e2losercom <- e2cace[e2cace$loser =="1",]

#building all the models
#empowerment
m1 <- lm(int_eff_ind_e1 ~ facilitation + 
           uptake, data=e1cace) #model e1 internal efficacy

m3<- lm(Con_eff_e1 ~ facilitation + 
          uptake, data=e1cace) #model e1 int efficacy spec

m5<- lm(acc_e1 ~ facilitation + 
          uptake, data=e1cace) #model e1 access

m2<- lm(Int_eff_indv_e2 ~ facilitation + 
          uptake, data=e2cace) #model e2 internal efficacy

m4<- lm(Con_eff_e2 ~ facilitation + 
          uptake, data=e2cace) #model e2 int efficacy spec

m6<- lm(acc_e2 ~ facilitation + 
          uptake, data=e2cace)#model e2 access

#empowerment losers
m7<- lm(int_eff_ind_e1 ~ facilitation + 
          uptake, data=e1losercom) #loser e1 int eff

m9<- lm(Con_eff_e1 ~ facilitation + 
          uptake, data=e1losercom) #loser e1 int eff spec!!!!!

m11<- lm(acc_e1 ~ facilitation + 
           uptake, data=e1losercom) #loser e1 access


m8<- lm(Int_eff_indv_e2 ~ facilitation + 
          uptake, data=e2losercom)  #loser e2 int eff

m10<-lm(Con_eff_e2 ~ facilitation + 
          uptake, data=e2losercom) #loser e2 int eff spec!!!!!

m12<- lm(acc_e2 ~ facilitation + 
           uptake, data=e2losercom) #loser e2 access

#support
f1 <- lm(tru_e1 ~ facilitation + 
           uptake, data=e1cace) #model e1 trust

f3<- lm(ex_eff_e1 ~ facilitation + 
          uptake, data=e1cace) #model e1 external efficacy


f2 <- lm(tru_e2 ~ facilitation + 
           uptake, data=e2cace) #model e2 trust

f4<- lm(ex_eff_e2 ~ facilitation + 
          uptake, data=e2cace) #model e2 external efficacy


#support losers
f5 <- lm(tru_e1 ~ facilitation + 
           uptake, data=e1losercom) #loser e1 trust

f7 <- lm(ex_eff_e1 ~ facilitation + 
           uptake, data=e1losercom) #loser e1 external efficacy


f6 <- lm(tru_e2 ~ facilitation + 
           uptake, data=e2losercom) #loser e2 trust

f8 <- lm(ex_eff_e2 ~ facilitation + 
           uptake, data=e2losercom) #loser e2 external efficacy

#making coefficient tables
#table support cace analysis
tab_model(f1, f2, f3, f4, terms = c("facilitation1", "uptake1"), 
          pred.labels = c("Invitation", "Uptake"), 
          dv.labels = c("f1"="Trust 1", "f2"="Trust 2", 
                        "f3"="External Efficacy 1", "f4"="External Efficacy 2"), 
          string.pred="Treatments",
          string.est="Coefficient (SE)", p.style="numeric_stars",
          auto.label = TRUE, show.ci = FALSE, collapse.se=TRUE,
          title="Table 6. CACE effects on support (full sample)")

#table empowerment cace analysis
tab_model(m1, m2, m3, m4, m5, m6, terms = c("facilitation1", "uptake1"), 
          pred.labels = c("Invitation", "Uptake"), 
          dv.labels = c("m1"="Internal Efficacy (General) 1", "m2"="Internal Efficacy (General) 2", 
                        "m3"="Internal Efficacy (Specific) 1", "m4"="Internal Efficacy (Specific) 2",
                        "m5"="Access 1", "m6"="Access 2"), string.pred="Treatments",
          string.est="Coefficient (SE)", p.style="numeric_stars",
          auto.label = TRUE, show.ci = FALSE, show.fstat = TRUE, collapse.se=TRUE,
          title="Table 7. CACE effects on empowerment (full sample)")

#table loser support
tab_model(f5, f6, f7, f8, terms = c("facilitation1", "uptake1"), 
          pred.labels = c("Invitation", "Uptake"), 
          dv.labels = c("fav5"="Trust 1", "fav6"="Trust 2", 
                        "fav7"="External Efficacy 1", "fav8"="External Efficacy 2"), 
          string.pred="Treatments",
          string.est="Coefficient (SE)", p.style="numeric_stars",
          auto.label = TRUE, show.ci = FALSE, collapse.se=TRUE,
          title="Table 8. CACE effects on support (subsample losers)")

#table loser empowerment cace analysis
tab_model(m7, m8, m9, m10, 
          m11, m12, terms = c("facilitation1", "uptake1"), 
          pred.labels = c("Invitation", "Uptake"), 
          dv.labels = c("m7"="Internal Efficacy (General) 1", "m8"="Internal Efficacy (General) 2", 
                        "m9"="Internal Efficacy (Specific) 1", "m10"="Internal Efficacy (Specific) 2",
                        "m11"="Access 1", "m12"="Access 2"), string.pred="Treatments",
          string.est="Coefficient (SE)", p.style="numeric_stars",
          auto.label = TRUE, show.ci = FALSE, collapse.se=TRUE,
          title="Table 9. CACE effects on empowerment (subsample losers)")

#DESCRIPTIVE STATISTICS#
#overview of the means
descripe1<-describe(exp1cltibble) #give summary statistics of each variable
view(descripe1)
table(exp1cltibble$gender)
table(exp1cltibble$edu)
table(exp1cltibble$lr_plac)
table(exp1cltibble$exper_2)
table(exp1cltibble$pref_e1)
table(exp1cltibble$imp_e1)

exp1cltibble <- exp1cltibble%>% as_tibble(.) %>% #calculating the sd of lr_place without don't know =99
  mutate(lr = dplyr::case_when(
    lr_plac==1 ~ 1,
    lr_plac==2 ~ 2,
    lr_plac==3 ~ 3,
    lr_plac==4 ~ 4,
    lr_plac==5 ~ 5,
    lr_plac==6 ~ 6,
    lr_plac==7 ~ 7))

view(exp1cltibble)
sd(exp1cltibble$lr, na.rm = TRUE)

table(exp2cltibble$pref_e2)
descripe2 <- describe(exp2cltibble)
view(descripe2)
